<?php

$all_modules = $modules->getAllModules();
$inst_modules = array();

?>
<div class="moduleTopNav">
	<h2><?php $lang->put('installed-modules'); ?></h2>
</div>
<table class="datatable">
	<thead>
		<tr>
			<td>&nbsp;</td>
			<td><?php $module->printSortLink($lang->get('module-name'), 'name'); ?></td>
			<td><?php $module->printSortLink($lang->get('description'), 'description'); ?></td>
			<td><?php $module->printSortLink($lang->get('version'), 'version'); ?></td>
			<td><?php $module->printSortLink($lang->get('author'), 'author'); ?></td>
			<td><?php $module->printSortLink($lang->get('module-url'), 'module_url'); ?></td>
			<td><?php $module->printSortLink($lang->get('type'), 'type'); ?></td>
			<td><?php $module->printSortLink($lang->get('installed-at'), 'installed_at'); ?></td>
			<td><?php $module->printSortLink($lang->get('installed-by'), 'installed_by'); ?></td>
		</tr>
	</thead>
	<tbody>
		<?php
		
		$structure = array('name', 'description', 'version', 'author', 'module_url', 'type', 'installed_at', 'installed_by');
		$module->setStructure($structure);
		
		$res = $module->queryData("SELECT * FROM ".$db->table('modules'), false);
		
		if(mysql_num_rows($res)) {
			while($row = mysql_fetch_array($res)) {
				
				$inst_modules[] = $row['path'];
				
				$data = array(	'id'				=> stripslashes($row['id'])
								,'name'				=> stripslashes($row['name'])
								,'description'		=> stripslashes($row['description'])
								,'version'			=> stripslashes($row['version'])
								,'author'			=> stripslashes($row['author'])
								,'module_url'		=> stripslashes($row['module_url'])
								,'type'				=> stripslashes($row['type'])
								,'installed_at'		=> $cosa->datetime($row['installed_at'])
								,'installed_by'		=> $user->authorLink($row['installed_by'])
								);
				$module->printTableRow($data, false, false);
				
			}
		} else {
			$module->printEmptyTableRow($lang->get('no-items-found'));
		}
		
		?>
	</tbody>
</table>
<br />

<?php if(count($inst_modules) < count($all_modules)) { ?>
<div class="moduleTopNav">
	<h2><?php $lang->put('uninstalled-modules'); ?></h2>
</div>
<table class="datatable">
	<thead>
		<tr>
			<td>&nbsp;</td>
			<td><?php $lang->put('module-name'); ?></td>
			<td><?php $lang->put('description'); ?></td>
			<td><?php $lang->put('version'); ?></td>
			<td><?php $lang->put('author'); ?></td>
			<td><?php $lang->put('module-url'); ?></td>
			<td><?php $lang->put('type'); ?></td>
		</tr>
	</thead>
	<tbody>
		<?php
		
		$structure = array('name', 'description', 'version', 'author', 'module_url', 'type');
		$module->setStructure($structure);
		
		foreach($all_modules as $k => $v) {
			
			$row = $modules->getModuleInformation($v['path'], false);
			if($row && !in_array($v['path'], $inst_modules)) {
				
				$data = array(	'id'				=> 0
								,'name'				=> stripslashes($row['name'])
								,'description'		=> stripslashes($row['description'])
								,'version'			=> stripslashes($row['version'])
								,'author'			=> stripslashes($row['author'])
								,'module_url'		=> stripslashes($row['module_url'])
								,'type'				=> $v['type']
								);
				$module->printTableRow($data, '&install='.$v['path'], false, false, true, $lang->get('install-module'));
				
			}
		}
		
		?>
	</tbody>
</table>
<br />
<?php } ?>

<h2><?php $lang->put('download-modules-title'); ?></h2>
<p><?php $lang->put('download-modules'); ?></p>

